Always pass `-C metadata` to the compiler
authorAlex Crichton <alex@alexcrichton.com>
Tue, 2 Aug 2016 06:22:29 +0000 (23:22 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 2 Aug 2016 06:22:29 +0000 (23:22 -0700)
If it's not otherwise available we just key it off the pkgid which should be
unique enough across compilations. This should help incremental compilation
efforts be "more incremental" across projects.

Closes #2943

src/cargo/ops/cargo_rustc/mod.rs
tests/build-lib.rs
tests/build-script.rs
tests/build.rs
tests/cargo_alias_config.rs
tests/cross-compile.rs
tests/profiles.rs
tests/run.rs
tests/rustc.rs

index 7dfa8ff45adf17120dbc496f2a5f513fff424ace..a743315b2480f0a10a42fe18e8e7c27a65da1b85 100644 (file)
@@ -9,7 +9,7 @@ use core::{Package, PackageId, PackageSet, Target, Resolve};
 use core::{Profile, Profiles, Workspace};
 use core::shell::ColorConfig;
 use util::{self, CargoResult, human};
-use util::{Config, internal, ChainError, profile, join_paths};
+use util::{Config, internal, ChainError, profile, join_paths, short_hash};
 
 use self::job::{Job, Work};
 use self::job_queue::JobQueue;
@@ -554,9 +554,14 @@ fn build_base_args(cx: &Context,
         }
     }
 
-    if let Some(m) = cx.target_metadata(unit) {
-        cmd.arg("-C").arg(&format!("metadata={}", m.metadata));
-        cmd.arg("-C").arg(&format!("extra-filename={}", m.extra_filename));
+    match cx.target_metadata(unit) {
+        Some(m) => {
+            cmd.arg("-C").arg(&format!("metadata={}", m.metadata));
+            cmd.arg("-C").arg(&format!("extra-filename={}", m.extra_filename));
+        }
+        None => {
+            cmd.arg("-C").arg(&format!("metadata={}", short_hash(unit.pkg)));
+        }
     }
 
     if rpath {
index 3d8a44108dc4f71231fa49d1d66b93bd30b7c114..f0390194b22f296b5119058e41ff03ec45b513fa 100644 (file)
@@ -10,6 +10,7 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
     format!("\
 [COMPILING] {name} v{version} ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
index 3cc250af3f1b80f92a818c8f971a09f78473cc00..6c52e97c52a675d010f56d998ab66ed18b02a001 100644 (file)
@@ -766,15 +766,17 @@ fn build_cmd_with_a_build_cmd() {
 [RUNNING] `rustc a[..]build.rs [..] --extern b=[..]`
 [RUNNING] `[..]a-[..]build-script-build[..]`
 [RUNNING] `rustc [..]lib.rs --crate-name a --crate-type lib -g \
+    -C metadata=[..] \
     --out-dir [..]target[..]deps --emit=dep-info,link \
     -L [..]target[..]deps`
 [COMPILING] foo v0.5.0 (file://[..])
 [RUNNING] `rustc build.rs --crate-name build_script_build --crate-type bin \
-    -g --out-dir [..] --emit=dep-info,link \
+    -g -C metadata=[..] --out-dir [..] --emit=dep-info,link \
     -L [..]target[..]deps \
     --extern a=[..]liba[..].rlib`
 [RUNNING] `[..]foo-[..]build-script-build[..]`
 [RUNNING] `rustc [..]lib.rs --crate-name foo --crate-type lib -g \
+    -C metadata=[..] \
     --out-dir [..] --emit=dep-info,link \
     -L [..]target[..]deps`
 [FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
index aa3ec6e6643bfae93432f1f67c1927db59626a98..fc0c754f3de0b9fa27c8ef494bb60d7dbb9bfb60 100644 (file)
@@ -1024,6 +1024,7 @@ fn lto_build() {
 [RUNNING] `rustc src[..]main.rs --crate-name test --crate-type bin \
         -C opt-level=3 \
         -C lto \
+        -C metadata=[..] \
         --out-dir {dir}[..]target[..]release \
         --emit=dep-info,link \
         -L dependency={dir}[..]target[..]release[..]deps`
@@ -1050,6 +1051,7 @@ fn verbose_build() {
                 execs().with_status(0).with_stderr(&format!("\
 [COMPILING] test v0.0.0 ({url})
 [RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}[..]target[..]debug[..]deps`
@@ -1077,6 +1079,7 @@ fn verbose_release_build() {
 [COMPILING] test v0.0.0 ({url})
 [RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib \
         -C opt-level=3 \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}[..]target[..]release[..]deps`
@@ -1120,12 +1123,14 @@ fn verbose_release_build_deps() {
 [RUNNING] `rustc foo[..]src[..]lib.rs --crate-name foo \
         --crate-type dylib --crate-type rlib -C prefer-dynamic \
         -C opt-level=3 \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}[..]target[..]release[..]deps`
 [COMPILING] test v0.0.0 ({url})
 [RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib \
         -C opt-level=3 \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}[..]target[..]release[..]deps \
index c026382e4d005c829c6fe1dcfb8393152c4e742c..6593d28f08e9761823f1d7c2c84a26bb17272d22 100644 (file)
@@ -55,8 +55,7 @@ fn alias_config() {
     assert_that(p.cargo_process("b-cargo-test").arg("-v"),
                 execs().with_status(0).
                 with_stderr_contains("[COMPILING] foo v0.5.0 [..]
-[RUNNING] `rustc [..] --crate-name foo --crate-type \
-bin -g --out-dir [..] --emit=dep-info,link -L dependency=[..]"));
+[RUNNING] `rustc [..] --crate-name foo [..]"));
 }
 
 #[test]
@@ -74,9 +73,7 @@ fn alias_list_test() {
     assert_that(p.cargo_process("b-cargo-test").arg("-v"),
                 execs().with_status(0).
                 with_stderr_contains("[COMPILING] foo v0.5.0 [..]").
-                with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo \
-                                     --crate-type bin -C opt-level=3 --out-dir [..]\
-                                     --emit=dep-info,link -L dependency=[..]")
+                with_stderr_contains("[RUNNING] `rustc [..] --crate-name [..]")
                 );
 }
 
@@ -95,9 +92,7 @@ fn alias_with_flags_config() {
     assert_that(p.cargo_process("b-cargo-test").arg("-v"),
                 execs().with_status(0).
                 with_stderr_contains("[COMPILING] foo v0.5.0 [..]").
-                with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo \
-                                     --crate-type bin -C opt-level=3 --out-dir [..]\
-                                     --emit=dep-info,link -L dependency=[..]")
+                with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo [..]")
                 );
 }
 
index 55371af3afcc454e66c5cb78bbc7d57173d85143..fa09e451b4bc2eff6ae10b380f932841d0b9baa3 100644 (file)
@@ -358,6 +358,7 @@ fn linker_and_ar() {
                        .with_stderr_contains(&format!("\
 [COMPILING] foo v0.5.0 ({url})
 [RUNNING] `rustc src[..]foo.rs --crate-name foo --crate-type bin -g \
+    -C metadata=[..] \
     --out-dir {dir}[..]target[..]{target}[..]debug \
     --emit=dep-info,link \
     --target {target} \
index 52fe001972f87b0211fb8274eaf047318f4b8856..3b86a7672b9286bf473fb864c8ddb7a943cc62cd 100644 (file)
@@ -30,6 +30,7 @@ fn profile_overrides() {
 [RUNNING] `rustc src{sep}lib.rs --crate-name test --crate-type lib \
         -C opt-level=1 \
         -C debug-assertions=on \
+        -C metadata=[..] \
         -C rpath \
         --out-dir [..] \
         --emit=dep-info,link \
@@ -83,6 +84,7 @@ fn top_level_overrides_deps() {
         --crate-type dylib --crate-type rlib -C prefer-dynamic \
         -C opt-level=1 \
         -g \
+        -C metadata=[..] \
         --out-dir {dir}{sep}target{sep}release{sep}deps \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}release{sep}deps`
@@ -90,6 +92,7 @@ fn top_level_overrides_deps() {
 [RUNNING] `rustc src{sep}lib.rs --crate-name test --crate-type lib \
         -C opt-level=1 \
         -g \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}release{sep}deps \
index 90e195f6eeae489f53c5234645635fea204200c7..1f76df20dcdae9f2f28698a6d0bfe0b515d338e9 100644 (file)
@@ -411,12 +411,14 @@ fn example_with_release_flag() {
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc bar{sep}src{sep}bar.rs --crate-name bar --crate-type lib \
         -C opt-level=3 \
+        -C metadata=[..] \
         --out-dir {dir}{sep}target{sep}release{sep}deps \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}release{sep}deps`
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc examples{sep}a.rs --crate-name a --crate-type bin \
         -C opt-level=3 \
+        -C metadata=[..] \
         --out-dir {dir}{sep}target{sep}release{sep}examples \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}release{sep}deps \
@@ -437,12 +439,14 @@ fast2"));
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc bar{sep}src{sep}bar.rs --crate-name bar --crate-type lib \
         -g \
+        -C metadata=[..] \
         --out-dir {dir}{sep}target{sep}debug{sep}deps \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc examples{sep}a.rs --crate-name a --crate-type bin \
         -g \
+        -C metadata=[..] \
         --out-dir {dir}{sep}target{sep}debug{sep}examples \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps \
index 79e49fdab08617b07ee2cbd6b9681ab1f1775936..ce9c6213555159c73d1e8030176864f7d369d71a 100644 (file)
@@ -30,6 +30,7 @@ fn build_lib_for_foo() {
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
@@ -60,6 +61,7 @@ fn lib() {
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
         -C debug-assertions=off \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
@@ -89,11 +91,13 @@ fn build_main_and_allow_unstable_options() {
                 .with_stderr(&format!("\
 [COMPILING] {name} v{version} ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
 [RUNNING] `rustc src{sep}main.rs --crate-name {name} --crate-type bin -g \
         -C debug-assertions \
+        -C metadata=[..] \
         --out-dir [..] \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug{sep}deps \
@@ -152,6 +156,7 @@ fn build_with_args_to_one_of_multiple_binaries() {
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..]`
 [RUNNING] `rustc src{sep}bin{sep}bar.rs --crate-name bar --crate-type bin -g \
         -C debug-assertions [..]`
@@ -207,6 +212,7 @@ fn build_with_args_to_one_of_multiple_tests() {
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
+        -C metadata=[..] \
         --out-dir [..]`
 [RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \
         -C debug-assertions [..]--test[..]`